package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Classname ShopController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/7/2 17:29
 * @Created by Ren
 */
@RestController(value = "adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    public static final String SHOP_STATUS = "SHOP_STATUS";

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 用户端修改店铺营业状态
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setStatus(@PathVariable Integer status){

        log.info("管理端设置店铺的营业状态为: {}",status == 1 ? "营业中" : "打样中");

        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(SHOP_STATUS,status);
        return Result.success();
    }

    /**
     * 管理端获取店铺营业状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer)valueOperations.get(SHOP_STATUS);
        log.info("管理管获取店铺的营业状态为: {}",status == 1 ? "营业中" : "打样中");
        return Result.success(status);
    }

}
